
/* vue */
import { ref } from 'vue';
import { EmitFn } from 'vue/types/v3-setup-context';
/* model */
import { SettingTableEventEnum } from '@src/modules/setting/gpt/model';

function useSettingListPage(emit?: EmitFn) {
  
  const defaultPageNum = 1
  const defaultPageSize = 10
  
  const pageNum = ref(defaultPageNum)
  const pageSize = ref(defaultPageSize)
  
  const setPageNum = (value: number) => {
    pageNum.value = value
  }
  
  const setPageSize = (value: number) => {
    pageSize.value = value
  }
  
  const initPageNum = () => {
    setPageNum(defaultPageNum)
  }
  
  const initPageSize = () => {
    setPageSize(defaultPageSize)
  }
  
  const initPage = () => {
    initPageNum()
    initPageSize()
  }
  
  const resetPage = () => {
    initPage()
  }
  
  const getPageNum = () => {
    return pageNum.value
  }
  
  const getPageSize = () => {
    return pageSize.value
  }
  
  const handlerPageNumChange = (pageNum: number) => {
    emit?.(SettingTableEventEnum.ChangePageNum, pageNum)
  }
  
  const handlerPageSizeChange = (pageSize: number) => {
    emit?.(SettingTableEventEnum.ChangePageSize, pageSize)
  }
  
  return {
    handlerPageNumChange,
    handlerPageSizeChange,
    getPageNum,
    getPageSize,
    setPageNum,
    setPageSize,
    resetPage,
    initPageNum
  }
}

export {
  useSettingListPage
}
